<template>
  <Card :title="pageTitle">
    <!-- <p>
      提交人：   张三
      发起时间：  2022/03/28  10:10:10
      部门：     商品总部
      供应商分类：合格供应商
    </p> -->
    <header>
      <el-row>
        <el-col :span="4">提交人：{{supplier.createUser}}</el-col>
        <el-col :span="4">发起时间：{{supplier.createTime}}</el-col>
        <el-col :span="4">部门：{{supplier.deptName}}</el-col>
        <el-col :span="4">供应商分类：{{supplier.supplierClassify}}</el-col>
      </el-row>
    </header>
    <el-row class="info">
      <el-col :span="12">
        <el-form ref="form" label-width="120px">
          <el-form-item label="供应商代码">
            <el-input :value="supplier.supplierCode" disabled></el-input>
          </el-form-item>
          <el-form-item label="供应商名称">
            <el-input :value="supplier.supplierName" disabled></el-input>
          </el-form-item>
          <el-form-item :label="reasonLabel">
            <el-input :value="reason" disabled></el-input>
          </el-form-item>
          <el-form-item label="操作原因">
            <el-input type="textarea" resize="none" :rows="10" :value="supplier.operateReason" autosize  disabled></el-input>
          </el-form-item>
          <el-form-item>
            <Button @click="handleBack()">返回上一层</Button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </Card>
</template>
<script>
import { mapState } from 'vuex';
import { getEliminateBillDetail } from '@/api/supplier/management/eliminateSupplier';
import { getBlacklistBillDetail } from '@/api/supplier/management/supplierBlacklist';
import { convertSupplierReasons } from '@/pages/supplier/constants'
import { SUPPLIER_CATEGORY_SELECT_LIST } from '@/pages/supplier/constants/common'
import { list2Obj } from '@/pages/supplier/utils';

const {
  ELIMINATION_REASONS_MAP_OBJECT,
  BLACKLIST_REASONS_MAP_OBJECT,
  CLUES_ELIMINATION_ACTIVATION_REASONS_MAP_OBJECT,
  POTENTIAL_ELIMINATION_ACTIVATION_REASONS_MAP_OBJECT,
  QUALIFIED_ELIMINATION_ACTIVATION_REASONS_MAP_OBJECT,
  POTENTIAL_BLACKLIST_ACTIVATION_REASONS_MAP_OBJECT,
  QUALIFIED_BLACKLIST_ACTIVATION_REASONS_MAP_OBJECT,
} = convertSupplierReasons

export default {
  data () {
    return {
      reason: '',
      pageTitle: '查看供应商',
      reasonLabel: '淘汰原因',
      supplier: {},
    }
  },
  mounted () {
    const { type, processId } = this.$route.query
    switch (type) {
      case 1:
      case '1':
        this.pageTitle = '查看黑名单供应商'
        this.reasonLabel = '拉黑原因'
        this.reason = BLACKLIST_REASONS_MAP_OBJECT[this.supplierItemData.reason]
        this.supplier = Object.assign({}, this.supplierItemData)
        break;
      case 2:
      case '2':
        this.pageTitle = '查看淘汰供应商'
        this.reasonLabel = '淘汰原因'
        this.reason = ELIMINATION_REASONS_MAP_OBJECT[this.supplierItemData.reason]
        this.supplier = Object.assign({}, this.supplierItemData)
        break;
      case 6:
      case '6':
        this.pageTitle = '查看黑名单供应商'
        this.reasonLabel = '拉黑原因'
        this.initBlacklistBill(processId)
        break;
      case 7:
      case '7':
        this.pageTitle = '查看激活供应商'
        this.reasonLabel = '激活原因'
        this.initBlacklistBill(processId)
        break;
      case 10:
        this.pageTitle = '查看淘汰供应商'
        this.reasonLabel = '淘汰原因'
        this.initEliminateBill(processId, 10)
        break;
      case '10':
      case 25:
        this.pageTitle = '查看淘汰供应商'
        this.reasonLabel = '淘汰原因'
        this.initEliminateBill(processId, 10)
        break;
      case '25':
      case 27:
        this.pageTitle = '查看淘汰供应商'
        this.reasonLabel = '淘汰原因'
        this.initEliminateBill(processId, 10)
        break;
      case '27':
      case 11:
      case '11':
      case 26:
      case '26':
      case 28:
      case '28':
        this.pageTitle = '查看激活供应商'
        this.reasonLabel = '激活原因'
        this.initEliminateBill(processId)
        break;
    }
  },
  computed: {
    ...mapState('supplier/baseList', ['supplierItemData'])
  },
  methods: {
    async initBlacklistBill (processId) {
      // const { supplierClassify } = this.$route.query
      const resp = await getBlacklistBillDetail({ processId })
      if (resp && resp.status === '0') {
        const { createUser, createTime, deptName, supplierCode, supplierName, reason, operateReason, supplierClassify } = resp.result
        this.supplier = {
          createUser,
          createTime,
          deptName,
          supplierClassify: list2Obj(SUPPLIER_CATEGORY_SELECT_LIST)[supplierClassify],
          supplierCode,
          supplierName,
          operateReason,
        }
        if (supplierClassify === 40331) {
          //  潜在
          this.reason = POTENTIAL_BLACKLIST_ACTIVATION_REASONS_MAP_OBJECT[reason]
        } else if (supplierClassify === 40332) {
          //  合格
          this.reason = QUALIFIED_BLACKLIST_ACTIVATION_REASONS_MAP_OBJECT[reason]
        }
      }
    },
    async initEliminateBill (processId, type) {
      // const { supplierClassify } = this.$route.query
      const resp = await getEliminateBillDetail({ processId })
      if (resp && resp.status === '0') {
        const { createUser, createTime, deptName, supplierCode, supplierName, reason, reasonDescription, supplierClassify } = resp.result
        this.supplier = {
          createUser,
          createTime,
          deptName,
          supplierClassify: list2Obj(SUPPLIER_CATEGORY_SELECT_LIST)[supplierClassify],
          supplierCode,
          supplierName,
          operateReason: reasonDescription,
        }
        if (type == 10) {
          this.reason = ELIMINATION_REASONS_MAP_OBJECT[reason]
        } else {
          if (supplierClassify === 40899) {
            // 线索
            this.reason = CLUES_ELIMINATION_ACTIVATION_REASONS_MAP_OBJECT[reason]
          } else if (supplierClassify === 40331) {
            //  潜在
            this.reason = POTENTIAL_ELIMINATION_ACTIVATION_REASONS_MAP_OBJECT[reason]
          } else if (supplierClassify === 40332) {
            //  合格
            this.reason = QUALIFIED_ELIMINATION_ACTIVATION_REASONS_MAP_OBJECT[reason]
          }
        }
      }
    },
    handleBack () {
      this.$router.go(-1)
    }
  },
  // beforeRouteEnter (to, from, next) {
  //   // 保存入口地址
  //   next((vm) => {
  //     vm.fromPageName = from.name
  //   })
  // },
  // beforeRouteLeave (to, from, next) {
  //   // 如果不是正常返回清空列表页面查询表单字段
  //   if (this.fromPageName !== to.name) {
  //     this.setFormItemData(null);
  //   }
  //   next()
  // }
}
</script>
<style scoped>
header {
  padding: 10px 0;
  margin-bottom: 20px;
  border-bottom: 1px solid #f1f1f1;
}
</style>
